<template>
  <div class="work main_block">
    <el-menu default-active="/work" mode="horizontal" :router="true">
      <el-menu-item index="/msg">消息</el-menu-item>
      <el-menu-item index="/work">待办</el-menu-item>
    </el-menu>
    <div class="switch">
      <el-radio-group v-model="userTaskStatus" @change="getWorks()">
        <el-radio-button :label="1">待处理</el-radio-button>
        <el-radio-button :label="2">已处理</el-radio-button>
      </el-radio-group>
    </div>
    <ul class="table">
      <li v-for="(work, index) in works" :key="index" @click="goDetail(work)">
        <div class="work_title">
          <i :class="work.bizType | getIcon" style="margin-right: 20px; font-size: 24px;"></i>
          <span>{{work.notifyContent}}</span>
        </div>
        <div class="time">{{work.createTime}}</div>
      </li>
      <li v-if="!works.length">暂无数据</li>
    </ul>
    <div class="pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :current-page="current"
        :page-size="size"
        :total="total"
        @current-change="pageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import httpSer from "@/http";
export default {
  data() {
    return {
      works: [],
      size: 13,
      total: 0,
      current: 1,
      userTaskStatus: 1
    };
  },
  created() {},
  mounted() {
    this.getWorks();
  },
  methods: {
    getWorks() {
      let url = "/userApproveTask/pageUserApproveTask";
      let data = {
        userTaskStatus: this.userTaskStatus,
        size: this.size,
        current: this.current
      };
      httpSer.post(url, data).then(res => {
        let works = res.records;
        this.works = works;
        this.total = res.total * 1;
        this.current = res.current * 1;
      });
    },
    pageChange(current) {
      this.current = current * 1;
      this.getWorks();
    },
    goDetail(work) {
        let path = "";
        let query = {
          id: work.bizId,
          bizType: work.bizType,
          status: 'approve',
          taskType: work.userTaskStatus
        };
        if (work.bizType == 1 || work.bizType == 2) {
          path = "project/projectDetail";
        } else if (work.bizType == 3) {
          path = "project/alterationDetail";
        }else if (work.bizType == 4) {
          path = "/task/taskApprove";
        } else if (work.bizType == 5) {
          path = "/task/taskDetail"
        } else {
          alert("未定义bizType");
        }
        this.$router.push({
          path,
          query: query
        });
      }
  },
  filters: {
    getIcon(bizType) {
      switch (bizType) {
        case 1:
          return "el-icon-circle-plus c_purple";
          break;
        case 2:
          return "el-icon-success c_green";
          break;
        case 3:
          return "el-icon-warning c_yellow";
          break;
        default:
          return "el-icon-info c_blue";
          break;
      }
    }
  },
  components: {}
};
</script>

<style lang="less" scope>
@import "./index.less";
</style>